const request=require('../../util/request.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    list:[],
    status:0,//状态
    pay_ticket_status:0,//库存取用量
    reproduction_num:0,//重新生产
    repair_num:0,//维修数量
    rb_num:0,//让步接收数量
    take_stock:0,//库存取用数量
    add_ticket:0,//剩余是否加入采购单，1加入
    remove_this:0,//是否将此项移除采购单，传1移除
    checked: false//
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      let tmp = {
        id:options.id
      }
      var that = this
      request.requestGet('order/handle_invalid',tmp, '',function (res) {
        that.setData({
          // list:res.data.ticket
          id:options.id,
          status:res.data.handle.status,
          remove_this:res.data.handle.pay_ticket_status,
          list:res.data
        })
        that.setData({
        })
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  //设置库存启用
  bindKeyInputVant1(e){
    this.setData({pay_ticket_status:e.detail})
  },





  onSwitchChange(e) {
    // e.detail 为当前开关状态
    console.log(e,"eeeeeeeee")
    // this.setData({ remove_this: e.detail });
    if(e.detail === true){
      console.log("qqqqqqqqq")
      this.setData({checked:true})
    }else{
      console.log("222222222")

      this.setData({checked:false})
    }
  },
  submit(e){
    let tmpstatus = Number(this.data.status)
    let tmprb_num = Number(this.data.rb_num)
    let tmprepair_num = Number(this.data.repair_num)
    let tmpreproduction_num = Number(this.data.reproduction_num)
    let tmptake_stock = Number(this.data.take_stock)
    let tmpadd_ticket = Number(this.data.add_ticket)
    if(this.data.checked === true){
      tmpadd_ticket = 1
    }else{
      tmpadd_ticket = 0
    }
    let tmpremove_this = Number(this.data.remove_this)
    let tmpId = this.data.list.handle.id
    let tmp = {
      status:tmpstatus,
      rb_num:tmprb_num,
      repair_num:tmprepair_num,
      reproduction_num:tmpreproduction_num,
      take_stock:tmptake_stock,
      add_ticket:tmpadd_ticket,
      remove_this:tmpremove_this,
      id:tmpId,
    }
    request.requestAjax('order/handle_invalid', tmp, "提交中", function(res) {
      if (res.status == 200) {
          wx.showToast({
            title: '提交成功',
            icon: 'success',
          })
          setTimeout(() => {
            wx.navigateBack()
          }, 1000)
      } else {
          wx.showToast({
              title: res.msg,
              icon: "none"
          })
      }

  }, function(res) {
      wx.showToast({
          title: '请求失败',
          icon: "none"
      })
  });


  },
  reproduction_num(e){
    this.setData({reproduction_num:e.detail})
  },
  repair_num(e){
    this.setData({repair_num:e.detail})
  },
  rb_num(e){
    this.setData({rb_num:e.detail})
  },

  projectinfo(e){
    var that = this
        wx.showModal({
        title: '提示',
        content: '移除采购单吗',
        success: function (res) {
          if(res.confirm){
            that.setData({
              remove_this:1
            })
            that.submit()
          }
          //   that.setData({
          //       remove_this:1
          //   })
          //   that.submit()
          // })
        }
    })
  } 

  
})